package com.example.tanlee.ocrgraduation.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.example.tanlee.ocrgraduation.application.MyApplication;
import com.example.tanlee.ocrgraduation.util.ImageUtil;
import com.example.tanlee.ocrgraduation.util.MyLog;


/**
 * 自定义头像,点击之后会出现大图
 * Created by tanlee on 2015/12/29.
 */
public class UserHeaderImageView extends ImageView implements View.OnClickListener {

    private MyLog log = MyLog.tanliLog();
    private String url;  // 显示图片的url
    private boolean isClickable = true;
//    public PaintFlagsDrawFilter mPaintFlagsDrawFilter;// 毛边过滤
//    Paint paint;
    private Context context;
    private Activity activity;

    public UserHeaderImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    public UserHeaderImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public UserHeaderImageView(Context context) {
        super(context);
        init(context);
    }

    public void init(Context context) {
        this.context = context;
        this.setOnClickListener(this);
    }

    @Override
    public void setImageBitmap(Bitmap bm) {
        super.setImageBitmap(ImageUtil.getRoundedCornerBitmap(bm));
    }


    @Override
    public void onClick(View v) {
        Intent intent;
        if (url == null)
            return;
//        if (url.equals("")) {
//            intent = new Intent(MyApplication.getInstance(), LoginActivity.class);
//            context.startActivity(intent);
//        } else {
//            if (activity != null){
//                OtherUtil.startDetailedInfo(this,activity,url);
//            }
//        }
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Activity getActivity() {
        return activity;
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }
}
